﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Moq;
using Universum.Infrastructure.Persistence;
using System.Security.Principal;
using TBlog = Universum.Model.Domain.Blogs.Blog;

namespace Universum.Unit.Tests.Controllers
{
	public class with_the_user_logged_in_and_no_blog_registered 
		: with_user_logged
	{
		
		internal IRepository Repository { get; set; }

		
		internal Mock<IRepository> RepositoryMock { get; set; }

		private string _owner;
		public with_the_user_logged_in_and_no_blog_registered()
		{
			
			//AsContext();
		}
		
		void AsContext()
		{
			RepositoryMock = arrange_repository_to_return_values_on(
				_owner,
				() => new TBlog[] { }.AsQueryable()
			);
			
			Repository = RepositoryMock.Object;
		}


		private static Mock<IRepository> arrange_repository_to_return_values_on(
			string owner,
			Func<IQueryable<TBlog>> function)
		{
			var repositoryMock = new Mock<IRepository>();

			//var blogByOwner = new Persistence.Queries.Blog.BlogByOwner(owner);

			repositoryMock.Setup(r => r.Query(It.IsAny<Universum.Infrastructure.Persistence.Queries.Blog.BlogByOwner>())).Returns(function).Verifiable();
			return repositoryMock;
		}

	

		protected override void EstablishContext()
		{
			base.EstablishContext();
			_owner = Principal.Identity.Name;
			AsContext();
		}
	}
}
